<?php
defined('_JEXEC') or die( 'Restricted access' );
jimport('joomla.application.component.model');
class QlchungModelDetail extends JModel{
	var $_data = null;
	
	function __construct(){
		parent::__construct();
	}
	function &getData(){
		$this->_loadData();
		
		return $this->_data;
	}
	function publish($cid = array(), $publish = 1)
	{
		$user 	=& JFactory::getUser();
		if (count( $cid ))
		{
			JArrayHelper::toInteger($cid);
			$cids = implode( ',', $cid );

			$query = 'UPDATE #__qlchung'
				. ' SET published = '.(int) $publish
				. ' WHERE id IN ( '.$cids.' )';
			$this->_db->setQuery( $query );
			if (!$this->_db->query()) {
				$this->setError($this->_db->getErrorMsg());
				return false;
			}
		}
		return true;
	}
	function store($data){
		$row =& $this->getTable('qlchung');
		if (!$row->bind($data)) {
			$this->setError($this->_db->getErrorMsg());			
			return false;
		}		
		if (!$row->store()) {
			echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";
			exit();
		}
		return true;
	}
		
	function _loadData(){
		if (empty($this->_data)){
			$query = 'SELECT * FROM #__qlchung';
			
			$this->_db->setQuery($query);
			$this->_data = $this->_db->loadObject();
			return (boolean) $this->_data;
		}
		return true;
	}
}